package net.entelijan.cobean.bind.impl;

import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

public class RowBeanXTestCase {

    @Test
    public void testTrue() {
        RowBeanX a = new RowBeanX("a", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX a1 = new RowBeanX("a", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX b = new RowBeanX("x", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX c = new RowBeanX("a", "b", "c", "d", 99, 1, 2, 3);
        Assert.assertTrue(a.equals(a));
        Assert.assertTrue(a.equals(a1));
        Assert.assertTrue(a1.equals(a));
        Assert.assertTrue(b.equals(b));
        Assert.assertTrue(c.equals(c));
    }

    @Test
    public void testFalse() {
        RowBeanX a = new RowBeanX("a", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX b = new RowBeanX("x", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX c = new RowBeanX("a", "b", "c", "d", 99, 1, 2, 3);
        Assert.assertFalse(a.equals(b));
        Assert.assertFalse(a.equals(c));
        Assert.assertFalse(a.equals(null));
        Assert.assertFalse(b.equals(a));
        Assert.assertFalse(b.equals(c));
    }

    @Test
    public void testListTrue() {
        RowBeanX a = new RowBeanX("a", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX a1 = new RowBeanX("a", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX b = new RowBeanX("x", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX c = new RowBeanX("a", "b", "c", "d", 99, 1, 2, 3);
        List<RowBeanX> la = buildList(a, a1, b, c);
        List<RowBeanX> la1 = buildList(a, a1, b, c);
        List<RowBeanX> la2 = buildList(a, a, b, c);
        List<RowBeanX> la3 = buildList(a1, a, b, c);
        List<RowBeanX> lb = buildList(b, a1, b, c);
        Assert.assertTrue(la.equals(la));
        Assert.assertTrue(lb.equals(lb));
        Assert.assertTrue(la1.equals(la));
        Assert.assertTrue(la.equals(la1));
        Assert.assertTrue(la.equals(la2));
        Assert.assertTrue(la.equals(la3));
        Assert.assertTrue(la3.equals(la2));
    }

    @Test
    public void testListFalse() {
        RowBeanX a = new RowBeanX("a", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX a1 = new RowBeanX("a", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX b = new RowBeanX("x", "b", "c", "d", 0, 1, 2, 3);
        RowBeanX c = new RowBeanX("a", "b", "c", "d", 99, 1, 2, 3);
        List<RowBeanX> la = buildList(a, a1, b, c);
        List<RowBeanX> lb = buildList(b, a1, b, c);
        List<RowBeanX> lb2 = buildList(b, a1, b, c, a);
        List<RowBeanX> lb1 = buildList(b, a1, b);
        Assert.assertFalse(la.equals(lb));
        Assert.assertFalse(lb.equals(la));
        Assert.assertFalse(lb.equals(lb1));
        Assert.assertFalse(lb.equals(lb2));
    }

    private List<RowBeanX> buildList(RowBeanX... vals) {
        ArrayList<RowBeanX> re = new ArrayList<RowBeanX>();
        for (RowBeanX val : vals) {
            re.add(val);
        }
        return re;
    }

}
